# Replication Code for: 
# "Reconciling National and Supranational Identities:
# Civilizationism in European Far-Right Discourse"

# Joseph Cerrone

# Perspectives on Politics

# Load Packages-----
library(tidyverse)
library(readr)
library(ggeffects)
library(jtools)
library(broom)
library(ggpubr)
library(stargazer)


# Import Data-----
# Add your own File Path
manifestos <- read_rds("~/Desktop/Research/Civilizationism/Replication Files/Manifestos.rds")
tweets <- read_rds("~/Desktop/Research/Civilizationism/Replication Files/Tweets.rds")


# Figure 1-----
manifestos_parfam <- manifestos %>%
  group_by(parfam_cmp) %>%
  summarise(n = n(),
            civ = sum(civ_numeric),
            civ_per = mean(civ_per))
manifestos_parfam$civ_prop <- (manifestos_parfam$civ/manifestos_parfam$n)*100

Figure1A <- ggplot(manifestos_parfam, aes(reorder(parfam_cmp, civ_prop), civ_prop)) +
  geom_col(fill = "black") +
  ylim(0, 35) +
  scale_x_discrete(breaks = c("NAT", "CON", "CHR", "SIP", "COM", 
                              "SOC", "ECO", "LIB", "ETH", "AGR"),
                   labels = c("Nationalist", "Conservative", "Christian Democratic",
                              "Special Interest", "Far Left", "Social Democratic", 
                              "Ecological", "Liberal", "Ethnic and Regional",
                              "Agrarian")) +
  coord_flip() +
  theme_classic() +
  theme(text = element_text(size = 9),
        axis.line = element_line(color = "black", size = 0.3),
        axis.ticks = element_line(color = "black", size = 0.3),
        axis.text = element_text(color = "black"),
        legend.position = "bottom") +
  labs(
    title = "",
    x = "",
    y = "% Manifestos"
  )

manifestos_fr <- manifestos %>%
  group_by(far_right) %>%
  summarise(n = n(),
            civ = sum(civ_numeric),
            civ_per = mean(civ_per))
manifestos_fr$civ_prop <- (manifestos_fr$civ/manifestos_fr$n)*100

Figure1B <- ggplot(manifestos_fr, aes(reorder(far_right, civ_prop), civ_prop)) +
  geom_col(fill = "black") +
  ylim(0, 35) +
  scale_x_discrete(breaks = c("0", "1"),
                   labels = c("Other", "Far Right")) +
  coord_flip() +
  theme_classic() +
  theme(text = element_text(size = 9),
        axis.line = element_line(color = "black", size = 0.3),
        axis.ticks = element_line(color = "black", size = 0.3),
        axis.text = element_text(color = "black"),
        legend.position = "bottom") +
  labs(
    title = "",
    x = "",
    y = "% Manifestos"
  )

# Add your own File Path
ggarrange(Figure1A, Figure1B,
          nrow = 1, ncol = 2) %>%
  ggsave(path = "~/Desktop/", 
       filename = "Figure 1.tif", width = 6.5, height = 3, device = 'tiff', dpi = 1200)


# Figure 2-----
Model1.1 <- glm(civ ~ parfam_cmp,
                data = manifestos, family = "binomial")
predict_model1.1 <- ggpredict(Model1.1, c("parfam_cmp"))
predict_model1.1 <- subset(predict_model1.1, x != "AGR")

Figure2A <- ggplot(predict_model1.1, aes(reorder(x, predicted), predicted)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), 
                  position = position_dodge(width = 0.5)) +
  ylim(0, 0.41) +
  scale_x_discrete(breaks = c("NAT", "CON", "CHR", "SIP", "COM", 
                              "SOC", "ECO", "LIB", "ETH", "AGR"),
                   labels = c("Nationalist", "Conservative", "Christian Democratic",
                              "Special Interest", "Far Left", "Social Democratic", 
                              "Ecological", "Liberal", "Ethnic and Regional",
                              "Agrarian")) +
  coord_flip() +
  theme_classic() +
  theme(text = element_text(size = 9),
        axis.line = element_line(color = "black", size = 0.1),
        axis.ticks = element_line(color = "black", size = 0.1),
        axis.text = element_text(color = "black"),
        legend.position = "bottom") +
  labs(
    title = "",
    x = "",
    y = "Predicted Probabilty"
  )

Model2.1 <- glm(civ ~ far_right,
                data = manifestos, family = "binomial")
predict_model2.1 <- ggpredict(Model2.1, c("far_right"))

Figure2B <- ggplot(predict_model2.1, aes(reorder(x, predicted), predicted)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), 
                  position = position_dodge(width = 0.5)) + 
  ylim(0, 0.41) +
  scale_x_discrete(breaks = c("0", "1"),
                   labels = c("Other", "Far Right")) +
  coord_flip() +
  theme_classic() +
  theme(text = element_text(size = 9),
        axis.line = element_line(color = "black", size = 0.1),
        axis.ticks = element_line(color = "black", size = 0.1),
        axis.text = element_text(color = "black"),
        legend.position = "bottom") +
  labs(
    title = "",
    x = "",
    y = "Predicted Probability"
  )

# Add your own File Path
ggarrange(Figure2A, Figure2B,
          nrow = 1, ncol = 2) %>%
  ggsave(path = "~/Desktop/", 
       filename = "Figure 2.tif", width = 6.5, height = 3, device = 'tiff', dpi = 1200)


# Figure 3-----
Model3.1 <- glm(civ ~ parfam_cmp,
                data = tweets, family = "binomial")
predict_model3.1 <- ggpredict(Model3.1, c("parfam_cmp"))

Figure3A <- ggplot(predict_model3.1, aes(reorder(x, predicted), predicted)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), 
                  position = position_dodge(width = 0.5)) +
  ylim(0, 0.002) +
  scale_x_discrete(breaks = c("NAT", "CON", "CHR", "SIP", "COM", 
                              "SOC", "ECO", "LIB", "ETH", "AGR"),
                   labels = c("Nationalist", "Conservative", "Christian Democratic",
                              "Special Interest", "Far Left", "Social Democratic", 
                              "Ecological", "Liberal", "Ethnic and Regional",
                              "Agrarian")) +
  coord_flip() +
  theme_classic() +
  theme(text = element_text(size = 9),
        axis.line = element_line(color = "black", size = 0.1),
        axis.ticks = element_line(color = "black", size = 0.1),
        axis.text = element_text(color = "black"),
        legend.position = "bottom") +
  labs(
    title = "",
    x = "",
    y = "Predicted Probabilty"
  )

Model4.1 <- glm(civ ~ far_right,
                data = tweets, family = "binomial")
predict_model4.1 <- ggpredict(Model4.1, c("far_right"))

Figure3B <- ggplot(predict_model4.1, aes(reorder(x, predicted), predicted)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), 
                  position = position_dodge(width = 0.5)) + 
  ylim(0, 0.002) +
  scale_x_discrete(breaks = c("0", "1"),
                   labels = c("Other", "Far Right")) +
  coord_flip() +
  theme_classic() +
  theme(text = element_text(size = 9),
        axis.line = element_line(color = "black", size = 0.1),
        axis.ticks = element_line(color = "black", size = 0.1),
        axis.text = element_text(color = "black"),
        legend.position = "bottom") +
  labs(
    title = "",
    x = "",
    y = "Predicted Probability"
  )

# Add your own File Path
ggarrange(Figure3A, Figure3B,
          nrow = 1, ncol = 2) %>%
  ggsave(path = "~/Desktop/", 
       filename = "Figure 3.tif", width = 6.5, height = 3, device = 'tiff', dpi = 1200)


# Table A1-----
# Based on author's research.

# Table A2-----
Model1.2 <- glm(civ ~ parfam_cmp + state,
                data = manifestos, family = "binomial")
Model1.3 <- glm(civ ~ parfam_cmp + year_cat,
                data = manifestos, family = "binomial")
Model1.4 <- glm(civ ~ parfam_cmp + state + year_cat,
                data = manifestos, family = "binomial")

TableA2 <- stargazer(Model1.1, Model1.2, Model1.3, Model1.4,
          omit = c("state", "year"),
          covariate.labels = c("Ecological", "Social Democratic", "Agrarian",
                               "Liberal", "Christian Democratic", "Conservative",
                               "Nationalist", "Ethnic", "Special Interest"),
          dep.var.caption = NULL,
          dep.var.labels = "Civilizationism",
          add.lines = list(c("Country FE", "No", "Yes", "No", "Yes"),
                           c("Year FE", "No", "No", "Yes", "Yes")),
          keep.stat = c("n", "aic"),
          type = "html",
          out = "Table A2.html")


# Table A3-----
Model2.2 <- glm(civ ~ far_right + state,
                data = manifestos, family = "binomial")
Model2.3 <- glm(civ ~ far_right + year_cat,
                data = manifestos, family = "binomial")
Model2.4 <- glm(civ ~ far_right + state + year_cat,
                data = manifestos, family = "binomial")

TableA3 <- stargazer(Model2.1, Model2.2, Model2.3, Model2.4,
          omit = c("state", "year"),
          covariate.labels = c("Far Right"),
          dep.var.caption = NULL,
          dep.var.labels = "Civilizationism",
          add.lines = list(c("Country FE", "No", "Yes", "No", "Yes"),
                           c("Year FE", "No", "No", "Yes", "Yes")),
          keep.stat = c("n", "aic"),
          type = "html",
          out = "Table A3.html")


# Table A4-----
Model3.2 <- glm(civ ~ parfam_cmp + state,
                data = tweets, family = "binomial")

TableA4 <- stargazer(Model3.1, Model3.2,
          omit = c("state"),
          dep.var.caption = NULL,
          dep.var.labels = "Civilizationism",
          add.lines = list(c("Country FE", "No", "Yes")),
          keep.stat = c("n", "aic"),
          type = "html",
          out = "Table A4.html")


# Table A5-----
Model4.2 <- glm(civ ~ far_right + state,
                data = tweets, family = "binomial")

TableA5 <- stargazer(Model4.1, Model4.2,
          omit = c("state"),
          covariate.labels = c("Far Right"),
          dep.var.caption = NULL,
          dep.var.labels = "Civilizationism",
          add.lines = list(c("Country FE", "No", "Yes")),
          keep.stat = c("n", "aic"),
          type = "html",
          out = "Table A5.html")

